<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>redis分布式锁测试</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
    <button id="shop">秒杀</button>
    <div id="count_num"></div>
    <div id="result"></div>
</body>
<script>
    var countNum = 0;
    $(function (){
        $("#shop").click(function (){
            var json = {"code":"test","countNum":200};
            for (var i= 0; i< 1000;i++){
                $.post("/test/miaosha",json,function (data){
                    if(data != "排队人数太多，请稍后再试."){
                        $("#result").append("<br />" + data + "<br />");
                    }else{
                        $("#result").append(data + " ");
                    }
                    if(data.indexOf("恭喜您，购买成功") != -1){
                        countNum += 200;
                    }
                    $("#count_num").text("总共卖出："+countNum);
                });
            }
        });
    });
</script>
</html>